import 'package:get/get.dart';
import 'package:number_spark_flutter/network/ns_api.dart';
import 'package:number_spark_flutter/network/ns_network_utils.dart';
import 'package:number_spark_flutter/routes/ns_app_pages.dart';
import 'package:number_spark_flutter/utils/ns_dialog_util.dart';
import 'package:number_spark_flutter/utils/ns_log_report_utils.dart';
import 'package:number_spark_flutter/utils/ns_user_utils.dart';

class NSSettingLogic extends GetxController {
  onLogout() async {
    NSDialogUtil.showConfirmDialog('Logout', description: 'Are you sure you want to logout?', sureAction: () async {
      NSResponseData responseData = await NSApi.logout.post({});
      if (responseData.isSuccess()) {
        NSNetWorkUtils.setAccessToken('');
        Get.offAllNamed(NSRoutes.login);
        NSLogReportUtils.stat(page: NSLogPages.nsLogout);
      }
    }, isDelete: true);
  }

  onDeleteAccount() async {
    NSDialogUtil.showConfirmDialog('Delete Account', description: 'Are you sure delete account', sureAction: () async {
      NSResponseData responseData = await NSApi.deleteAccount.post({});
      if (responseData.isSuccess()) {
        NSNetWorkUtils.setAccessToken('');
        Get.offAllNamed(NSRoutes.login);
        NSLogReportUtils.stat(page: NSLogPages.nsDeleteAccount);
      }
    }, isDelete: true);
  }
}
